package dao

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"time"
)

type Activity struct {
	Id        int64     `json:"id" gorm:"column:id;comment:自增id"`
	Title     string    `json:"title" gorm:"column:title;comment:活动标题"`
	Type      uint8     `json:"type" gorm:"column:type;comment:发布类型 0图文发布 1链接号发布"`
	Source    string    `json:"source" gorm:"column:source;comment:活动来源;"`
	Link      string    `json:"link" gorm:"column:link;comment:链接地址"`
	Images    []byte    `json:"images" gorm:"column:images;comment:活动图片"`
	Content   string    `json:"content" gorm:"column:content;comment:活动正文"`
	Text      string    `json:"text" gorm:"column:text;comment:正文"`
	Sort      int       `json:"sort" gorm:"column:sort;comment:排序"`
	IsDelete  uint8     `json:"is_delete" gorm:"column:is_delete;comment:1已删除"`
	Status    uint8     `json:"status" gorm:"column:status;comment:状态"`
	CreateBy  string    `json:"create_by" gorm:"column:create_by;comment:创建人"`
	UpdatedAt time.Time `json:"update_at" gorm:"column:update_at;comment:更新时间"`
	CreatedAt time.Time `json:"create_at" gorm:"column:create_at;comment:创建时间"`
}

func (f *Activity) TableName() string {
	return "activity"
}

// InitData 初始化activity表
func (f *Activity) InitData(tx *gorm.DB) error {
	return tx.AutoMigrate(f)
}

// Save 保存
func (f *Activity) Save(c *gin.Context, tx *gorm.DB) error {
	if err := tx.WithContext(c).Save(f).Error; err != nil {
		return err
	}
	return nil
}
